<script setup lang="ts">
import { ref } from 'vue';

import { useVbenDrawer } from '@vben/common-ui';

import QuestionManageTable from './components/question-manage-table.vue';

const emit = defineEmits<{ reload: [] }>();

const currQuestionnaireId = ref<any>();

const [BasicDrawer, drawerApi] = useVbenDrawer({
  // 在这里更改宽度
  class: 'w-[90%]',
  onClosed: handleClosed,
  // onConfirm: handleConfirm,
  onOpenChange: async (isOpen) => {
    if (!isOpen) {
      return null;
    }
    // drawerApi.drawerLoading(true);
    drawerApi.lock(true);
    //
    const { questionnaireId } = drawerApi.getData() as {
      questionnaireId?: number | string;
    };
    if (questionnaireId) {
      // 根据问卷id查询题目列表
      currQuestionnaireId.value = questionnaireId;
    }

    drawerApi.lock(false);
  },
});

async function handleClosed() {
  currQuestionnaireId.value = null;
  // await formApi.resetForm();
  // resetInitialized();
}

async function handleTagUpdated() {
  emit('reload');
}
</script>

<template>
  <BasicDrawer :footer="false" title="管理问卷题目">
    <QuestionManageTable
      :questionnaire-id="currQuestionnaireId"
      @reload="handleTagUpdated"
    />
  </BasicDrawer>
</template>
